package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 购物车控制器
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "C端~购物车控制器")
@Slf4j
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCarService;


    /**
     * 添加购物车(day07任务三)
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加购物车接口")
    public Result addCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("[添加购物车]dto:{}",shoppingCartDTO);
        shoppingCarService.addCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查看购物车(day07任务四)
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看购物车列表")
    public Result<List<ShoppingCart>> findShoppingCartList(){
        log.info("[获取购物车列表]");
        List<ShoppingCart> shoppingCartList = shoppingCarService.findCartList();
        return Result.success(shoppingCartList);
    }

    /**
     * 清空购物车(day07任务五)
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation("清除购物车")
    public Result cleanCart(){
        log.info("[清除购物车]");
        shoppingCarService.cleanCart();
        return Result.success();
    }
}
